<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var merge = function (intervals) {
        let result = []
        intervals.sort((a, b) => a[0] - b[0])
        let temp = intervals[0]
        for (let i = 0; i < intervals.length; i++) {
          if (temp[1] >= intervals[i][0]) {
            temp[1] = Math.max(temp[1], intervals[i][1])
          } else {
            result.push(temp)
            temp = intervals[i]
          }
        }
        result.push(temp)
        return result
      }
    </script>
  </body>
</html>
